 <!--
* description: 服务参数设置
* author: xiaochengzuan
* createdDate: 2021-2-24
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-table-cols="tableCols"
      :dynamic-api-config="apiConfig"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-show-more-btn="true"
    />

    <edit
      :key="editPopupsKey"
      :dynamic-edit-row-data="editRowData"
      :popups-visible.sync="editPopupsVisible"
      :popups-state="editPopupsState"
      :dynamic-api-style="'restful'"
      @close="close"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import OneTableTemplate from "@/components/templates/oneTable";
import Vue from "vue";
import { orgApis } from '@/api/sebasicdataapi'

export default {
  name: "serviceParameters",

  components: {
    OneTableTemplate,
    Edit: () => import("./edit"),
  },

  // 组件混入对象：{data[listQuery] methods[queryTable]}
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ""], function () {
      next();
    });
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path;

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode]);

    return {
      // 网格查询API配置对象
      apiConfig: orgApis.serviceParametersquery,
      editRowData: {},
      selectData: {},
      editPopupsVisible: false,
      titleName: "区域审核",
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          name: "search",
          clickEvent: () => this.queryTable(1),
          text: this.$t("sys.button.query"), // 查询
          position: "right",
          fuzzySearch: true,
        },
        {
          compKey: "btnKey2",
          type: "",
          size: "small",
          name: "reset",
          clickEvent: () => this.reset(),
          text: this.$t("sys.button.reset"),
          position: "right", // 重置
        },
        // {
        //   compKey: "btnKey3",
        //   size: "small",
        //   name: "add",
        //   clickEvent: () => this.add(),
        //   text: this.$t("sys.button.add"),
        //   position: "left", // 新增
        // },
        // {
        //   compKey: "comKey2",
        //   type: "",
        //   size: "small",
        //   name: "importTemplate",
        //   position: "left",
        //   // clickEvent: () => this.importtemp(),
        //   text: "导入",
        // },
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
              .tableComponents
          : [
            //   {
            //     compKey: "compKey1",
            //     labelName: "车系：",
            //     codeField: "colNtatusName",
            //     lookuptype: "VE1086",
            //     component: () => import("@/components/org/LookupValue"),
            //     type: "dropdownList",
            //     isMul: false,
            //     isMust: true,
            //   },
            //   {
            //     compKey: "compKey2",
            //     labelName: "车型：",
            //     codeField: "colNtatusName",
            //     lookuptype: "VE1086",
            //     component: () => import("@/components/org/LookupValue"),
            //     type: "dropdownList",
            //     isMul: false,
            //     isMust: true,
            //   },
              {
                compKey: "compKey1",
                labelName: "参数编号：",
                codeField: "serviceSysParaCode",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true,
              },
              {
                compKey: "compKey2",
                labelName: "参数名称：",
                codeField: "serviceSysParaName",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true,
              },
              {
                compKey: "compKey3",
                labelName: "参数类型：",
                codeField: "serviceSysParaType",

              customObj: {
                api: orgApis.serviceParametersselect,
              },
              component: () => import('@/components/org/commonSelect'),
                type: "dropdownList",
                isMul: false,
                isMust: true,
              },

                {
                compKey: "compKey4",
                labelName: "门店编码：",
                codeField: "dlrCode",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMul: false,
                isMust: true,
              },
            ],
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
              {
                prop: "subsidyId",
                label: "主键ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "updateControlId",
                label: "并发控制ID",
                hidden: true,
                alwaysHidden: true,
              },
              {
                prop: "controlBtn",
                label: "操作",
                width: 100,
                fixed: true,
                isComponent: true,
                comps: [
                  {
                    compKey: "propKey1",
                    labelName: "修改",
                    component: () => import("@/components/org/linkButton"),
                    clickEvent: (index) => this.edit(index)
                  },
                ],
              },
              {
                prop: "serviceSysParaCode",
                label: "参数编号",
              },
              {
                prop: "serviceSysParaName",
                label: "参数名称",
              },
              {
                prop: "serviceSysParaValue",
                label: "参数值",
              },
              {
                prop: "remark",
                label: "参数说明",
              },
              {
                prop: "serviceSysParaTypeCn",
                label: "参数类型",
              },
              {
                prop: "dlrCode",
                label: "门店编码",
              },
            ],

      // 表单数据
      formField: this.$utils.getFormField(
        this,
        {
          serviceSysParaCode:'',
          serviceSysParaName:'',
          serviceSysParaType:'',
          dlrCode:'',

        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      ),
    };
  },

  mounted() {
    this.$refs.multipleTable.list=[{'dlrFullNameC':1}]
    // 列表查询
    this.queryTable(1);
  },

  methods: {
    edit(index) {
      this.editPopupsState = 'edit'
      this.editPopupsVisible = true;
      this.editRowData = this.$refs["multipleTable"].list[index];
    },
    close() {
      this.editPopupsVisible = false;
      this.queryTable(1);
    },


  },
};
</script>
